<?php

namespace App\Listeners\Train\TrainOrder;

use App\Events\Train\TrainOrder\TrainOrderTicketedEvent;
use App\Models\Train\TrainOrders\Repositories\Interfaces\TrainOrdersRepositoryInterface;
use Exception;

class TrainOrderTicketedListener
{


    /**
     * Create the event listener.
     *
     * @return void
     */
    public function __construct()
    {

    }

    /**
     * Handle the event.
     *
     * @param object $event
     *
     * @return void
     * @throws Exception
     */
    public function handle(TrainOrderTicketedEvent $event)
    {
        $order_info     = $event->order;
        $orderQuery     = $event->orderQuery;
        $trainOrderRepo = app(TrainOrdersRepositoryInterface::class);
        switch ($order_info->order_service) {
            case 'piaochi':
                $trainOrderRepo->ticketed($order_info, [
                    'train'      => $orderQuery->getOrderTrain(),
                    'passengers' => $orderQuery->getOrderPassengers(),
                ]);
                break;
            default:
                throw new Exception("order service error ");
        }


    }


}
